package com.pishou.shop;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.MotionEvent;
import android.widget.TextView;

import com.pishou.player.R;

import java.util.Timer;
import java.util.TimerTask;

public class NoticeActivity extends Activity {

    private Timer timer;
    private TimerTask task;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_notice);
        Intent intent =  getIntent();
        TextView tv_notice =  findViewById(R.id.tv_notice);
        tv_notice.setText(intent.getStringExtra("notice"));
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        if (ev.getAction() == 0){
            finish();
        }
        return super.dispatchTouchEvent(ev);
    }

    @Override
    protected void onStart() {
        timer = new Timer();
        task = new TimerTask() {
            @Override
            public void run() {
                finish();
            }
        };
        timer.schedule(task,5*1000l);
        super.onStart();
    }

    @Override
    protected void onPause() {
        if (timer!=null){
            timer.cancel();
            timer = null;
        }
        if (task!=null){
            task.cancel();
            task = null;
        }
        super.onPause();
    }
}
